package com.yidu.best.systemManagement.resourceManagement.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yidu.best.systemManagement.resourceManagement.dao.ResourceDao;
import com.yidu.best.systemManagement.resourceManagement.domain.Resource;
import com.yidu.best.systemManagement.resourceManagement.service.ResourceService;
import com.yidu.best.systemManagement.resourceManagement.util.IDUtil;

@Service
public class ResourceServiceImpl implements ResourceService{
	@Autowired
	private ResourceDao resourceDao;

	@Override
	public Map<String, Object> findAll(Resource resource) {
		List<Resource> findAll = resourceDao.findAll(resource);
		for (Resource resource2 : findAll) {
			if (resource2.getParentId() == null) {
				resource2.setParentId("0");
			}
		}
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("data", findAll);
		map.put("msg", "");
		map.put("code", 0);
		return map;
	}

	@Override
	public int DeleteResource(String resourceId) throws DataAccessException {
		return resourceDao.DeleteResource(resourceId);
	}

	@Override
	public int AddResource(Resource resource) {
		resource.setResourceId(IDUtil.getUUID());
		resource.setUsable(1);
		return resourceDao.AddResource(resource);
	}

	@Override
	public int UpdateResource(Resource resource) {
		resourceDao.UpdateResource(resource);
		return 0;
	}

	@Override
	public List<Resource> selectAll() {
		return resourceDao.selectAll();
	}

	@Override
	public int Updateusable(Resource resource) {
		return resourceDao.Updateusable(resource);
	}

	
}
